package com.frame.pageform.job;

public class PoolThread extends Thread{

	private Job job;
	/**
	 * 0未启动、1正在执行任务、2睡眠、3停止
	 */
	private int thread_state=0;

	final public void run()
	{
		while(thread_state!=3){
			synchronized (this)
			{
				job.getRun().run();
				long time=System.currentTimeMillis();
				job.setLastTime(time);
				thread_state=2;
				try
				{
					//执行完之后线程睡眠，直到被唤醒
					wait();
				}
				catch (InterruptedException ex)
				{
				}
			}
		}
	}
	final synchronized public void run(Job job)
	{
		this.job = job;
		if (thread_state == 0)
		{
			thread_state = 1;
			start();
		}
		else if (thread_state == 2)
		{
			notify();
		}
	}
	/**
	 * 停止线程
	 */
	final synchronized void free()
	{
		thread_state = 3;
		notify();
	}
	public int getThread_state() {
		return thread_state;
	}

}
